<?php

namespace App\Models;

use App\Models\Scopes\ActiveScope;
use App\Models\Scopes\SortScope;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

class Tag extends Model
{
    protected $fillable = [
        'title',
        'show',
        'index',
    ];

    protected $casts = [
        'index' => 'int',
        'show' => 'bool',
    ];

    protected $attributes = [
        'show' => true,
    ];

    protected static function booted(): void
    {
        static::addGlobalScope(new ActiveScope);
        static::addGlobalScope(new SortScope);
    }

    public function videos(): BelongsToMany
    {
        return $this->belongsToMany(Video::class);
    }
}
